﻿
package extremefx.i18n {
	import extremefx.DateTime;
	import extremefx.TimeSpan;	
	/**
	 * @author Marcelo Volmaro
	 */
	internal class CCFixed {
		/**
		 * The method computes the <code>DateTime</code> from a fixed day number.
		 */
		internal static function _toDateTime(pDate:int):DateTime {
			var ticks:Number = (pDate - 1) * TimeSpan.TICKS_PER_DAY;
			return new DateTime(ticks);
		}
		
		internal static function _toDateTime2(pDate:int, pHour:int, pMinute:int, pSecond:int, pMSecond:int):DateTime {
			var time:DateTime = _toDateTime(pDate);
			time.addHours(pHour);
			time.addMinutes(pMinute);
			time.addSeconds(pSecond);
			time.addMilliseconds(pMSecond);
			return time;
		}
		
		/**
		 * A static method computing the fixed day number from a <code>DateTime</code> value.
		 */
		internal static function _fromDateTime(pTime:DateTime):int {
			return 1 + int(pTime.ticks / TimeSpan.TICKS_PER_DAY);
		}
		
		internal static function _dayOfWeek(pDate:int):int {
			return CCMath.mod(pDate, 7);
		}
		
		/**
		 * The static method computes the date of a day of week on or before a particular date.
		 */
		internal static function _kdayOnOrBefore(pDate:int, pK:int):int {
			return pDate - _dayOfWeek(pDate-pK);
		}
		
		/**
		 * The static method computes the date of a day of week on or after a particular date.
		 */
		internal static function _kdayOnOrAfter(pDate:int, pK:int):int {
			return _kdayOnOrBefore(pDate+6, pK);
		}
		
		/**
		 * The static method computes the date of a day of week that is nearest to a particular date.
		 */
		internal static function _kdNearest(pDate:int, pK:int):int {
			return _kdayOnOrBefore(pDate+3, pK);
		}
		
		/**
		 * The static method computes the date of a day of week after a particular date.
		 */
		internal static function _kdayAfter(pDate:int, pK:int):int {
			return _kdayOnOrBefore(pDate+7, pK);
		}
		
		/**
		 * The static method computes the date of a day of week before a particular date.
		 */
		internal static function _kdayBefore(pDate:int, pK:int):int {
			return _kdayOnOrBefore(pDate-1, pK);
		}
	}
}
